<?php
/** setup definitions */
define('PUBLIC_PATH', realpath(dirname(__FILE__)));
define('ROOT_PATH',   realpath(PUBLIC_PATH . '/../'));
define('APPLICATION_PATH', ROOT_PATH . '/application');
define('DATA_PATH', ROOT_PATH . '/data');

/** setup environment */
if(isset($_GET['env'])){
	$potentialEnv = strtolower($_GET['env']);
	if(in_array($potentialEnv, array('development','staging','production'))){
		define('APPLICATION_ENV', $potentialEnv);
	} else {
		throw new Exception("Environment must be either development, staging, or production.");
	}
} else {
	define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development');
}

/** setup inclusion path */
set_include_path(implode(PATH_SEPARATOR, array(
	ROOT_PATH . '/library',
	ROOT_PATH . '/library/incubator',
	get_include_path()
)));

/** setup bootstrap class */
$displayErrors = (int)(APPLICATION_ENV === 'development');
if(stristr($_SERVER['REQUEST_URI'],'install')){
	$bootstrapPath 		= APPLICATION_PATH . '/Installer.php';
	$bootstrapClass		= 'Bootstrap_Installer';
} else {
	$bootstrapPath 		= APPLICATION_PATH . '/Bootstrap.php';
	$bootstrapClass		= 'Bootstrap';
}

/** setup bootstrap config */
$bootstrapConfig = array(
    'bootstrap' => array(
        'path' => $bootstrapPath,
        'class' => $bootstrapClass
    ),
    'phpSettings' => array(
        'display_startup_errors' => $displayErrors,
        'display_errors' => $displayErrors
    )
);

/** setup application */
require_once 'Solvex/Application.php';
$application = new Solvex_Application(APPLICATION_ENV, $bootstrapConfig);

/** run application */
$application->bootstrap()->run();